import 'package:flutter/material.dart';

class AnimatedExample01Page extends StatefulWidget {
  const AnimatedExample01Page({super.key});

  @override
  State<AnimatedExample01Page> createState() => _AnimatedExample01PageState();
}

class _AnimatedExample01PageState extends State<AnimatedExample01Page> {
  bool flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Animated Example 01'),
      ),
      body: Center(
        child: Container(
          width: 300,
          height: 300,
          color: Colors.blue,
          child: AnimatedSwitcher(
            transitionBuilder: (child, animation) {
              return ScaleTransition(
                scale: animation,
                child: FadeTransition(
                  opacity: animation,
                  child: child,
                ),
              );
            },
            duration: const Duration(milliseconds: 1500),
            child: Text(
              key: UniqueKey(),
              flag ? "你好FLutter" : "你好，云享嘉",
              style: Theme.of(context).textTheme.headlineLarge,
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            flag = !flag;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
